﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Citi.Helpers;

namespace Citi.SecurityHelper
{
    public class SecurityDownload
    {
        public static void DownloadRemoteFile(string url, string fileName, string soeid, string proxy)
        {
            //var password = Citi.SecurityHelper.CitiPasswordFile.GetDecryptedPassword(soeid, LoginType.ActiveDirectory, SecurityConfigurations.RobotUserName, SecurityConfigurations.RobotPassword);
            var lines = Citi.SecurityHelper.CitiPasswordFile.GetDecryptedUserText(soeid, LoginType.ActiveDirectory, SecurityConfigurations.RobotUserName, SecurityConfigurations.RobotPassword);
            var user = lines.First().Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).Last();
            var domain = lines.First().Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).First();
            var password = lines.Last();

            WebHelper.DownloadRemoteFile(url, fileName, user, password, domain, proxy);
        }
    }
}
